Add Windows build system#28
Open
Eclips4 wants to merge 12 commits intoRust-for-CPython:3.15-rust-in-cpythonfrom
Open
Add Windows build system#28Eclips4 wants to merge 12 commits intoRust-for-CPython:3.15-rust-in-cpythonfrom
Eclips4 wants to merge 12 commits intoRust-for-CPython:3.15-rust-in-cpythonfrom
Conversation
|
I seem to have run into a build failure due to Rust and bindgen finding different clang installations: Error log
The following patch should fix it however: diff --git a/Modules/cpython-sys/build.rs b/Modules/cpython-sys/build.rs
index c34b99a771..03335128e9 100644
--- a/Modules/cpython-sys/build.rs
+++ b/Modules/cpython-sys/build.rs
@@ -56,6 +56,13 @@ fn emit_rerun_instructions(builddir: Option<&str>) {
/// headers. We pass -resource-dir to bindgen's clang so it picks up those
/// headers instead of the broken libclang-18 ones.
fn newest_clang_resource_dir() -> Option<PathBuf> {
+ // On Windows, derive the resource directory from LIBCLANG_PATH so that
+ // bindgen uses headers matching the libclang.dll it loads, rather than
+ // picking up a different, incompatible, system LLVM installation
+ if cfg!(windows) {
+ return clang_resource_dir_from_libclang_path();
+ }
+
let base = Path::new("/usr/lib");
let mut best: Option<(u32, PathBuf)> = None;
for entry in std::fs::read_dir(base).ok()?.flatten() {
@@ -76,6 +83,34 @@ fn newest_clang_resource_dir() -> Option<PathBuf> {
best.map(|(_, p)| p)
}
+/// Derive the clang resource directory from LIBCLANG_PATH.
+///
+/// When LIBCLANG_PATH points to e.g. `...\bin`, the resource directory is
+/// at `...\lib\clang\<version>`. We pick the highest version found.
+fn clang_resource_dir_from_libclang_path() -> Option<PathBuf> {
+ let libclang_path = env::var("LIBCLANG_PATH").ok()?;
+ let bin_dir = Path::new(&libclang_path);
+ // LIBCLANG_PATH typically points to a `bin` directory; the resource
+ // dir lives under the sibling `lib/clang/<version>`.
+ let clang_lib_dir = bin_dir.parent()?.join("lib").join("clang");
+ let mut best: Option<(u32, PathBuf)> = None;
+ for entry in std::fs::read_dir(&clang_lib_dir).ok()?.flatten() {
+ let name = entry.file_name();
+ let name = name.to_string_lossy();
+ // Version directories can be just a major number (e.g. "18") or
+ // a full dotted version (e.g. "18.1.3"). Parse the major part.
+ if let Ok(ver) = name.split('.').next().unwrap_or("").parse::<u32>() {
+ let resource_dir = entry.path();
+ if resource_dir.join("include").is_dir()
+ && best.as_ref().map_or(true, |(v, _)| ver > *v)
+ {
+ best = Some((ver, resource_dir));
+ }
+ }
+ }
+ best.map(|(_, p)| p)
+}
+
fn gil_disabled(srcdir: &Path, builddir: Option<&str>) -> bool {
if env_var_is_truthy("PY_GIL_DISABLED") {
return true;
I also expect we will need to install LLVM via the external dependencies system eventually. The JIT currently downloads LLVM21 so we probably want to do similarly for the bindings. That may make the above issue not a concern if we can just load libclang from the downloaded copy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.